package com.yuexun.dhdoctor.module.commun.bean;

import android.content.Context;

import com.yuexun.dhdoctor.config.AppConfig;
import com.yuexun.dhdoctor.module.Contract.bean.People;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangt on 2017/7/20.
 */

public class AllPeopleSelect {

    private static ArrayList<People> selectPeoples = new ArrayList<>();

    private Context context;

    public AllPeopleSelect(Context context) {
        this.context = context.getApplicationContext();
    }

    private static AllPeopleSelect instance = null;

    public static AllPeopleSelect newInstance(Context context) {
        if (null == instance) {
            instance = new AllPeopleSelect(context);
        }
        return instance;
    }

    public void setAllPeople(List<People> addPeople, List<People> delPeople) {
        if (addPeople != null && addPeople.size() != 0) {
//            Log.e("!!!!!!!!!!!!!!!!增加人员", addPeople.size() + "");

            List<People> removeList = new ArrayList<>();
            for (int i = 0; i < addPeople.size(); i++) {
                for (int j = 0; j < selectPeoples.size(); j++) {
                    if (addPeople.get(i).getUserId().equals(selectPeoples.get(j).getUserId())) {
                        removeList.add(addPeople.get(i));
                        break;
                    }
                }
            }
            addPeople.removeAll(removeList);

            for (People item : addPeople) {
                if (item.getUserId().equals(PreferenceHelper.readString(context, AppConfig.USER_INFO, AppConfig.USER_ID))) {
                    addPeople.remove(item);
                    break;
                }
            }
            selectPeoples.addAll(addPeople);
        }

        if (delPeople != null && delPeople.size() != 0) {
//            Log.e("!!!!!!!!!!!!!!!!删除人员", delPeople.size() + "");

            List<People> removeList = new ArrayList<>();
            for (int i = 0; i < selectPeoples.size(); i++) {
                for (int j = 0; j < delPeople.size(); j++) {
                    if (selectPeoples.get(i).getUserId().equals(delPeople.get(j).getUserId())) {
                        removeList.add(selectPeoples.get(i));
                        break;
                    }
                }
            }
            selectPeoples.removeAll(removeList);
        }
//        Log.e("!!!!!!!!!!!!!!!!全部选中人员", selectPeoples.size() + "");

    }

    public ArrayList<People> getAllpeople() {
        return selectPeoples;
    }

    public void clearAllPeople() {
        selectPeoples.clear();
    }
}
